package com.zhilei.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhilei.base.BaseInfoProperties;
import com.zhilei.mapper.ResumeWorkExpMapper;
import com.zhilei.pojo.ResumeWorkExp;
import com.zhilei.pojo.bo.EditWorkExpBO;
import com.zhilei.service.ResumeWorkExpService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

/**
 * <p>
 * 简历表 服务类
 * </p>
 *
 * @author 志磊
 * @since 2024-09-20
 */
@Slf4j
@Service
public class ResumeWorkExpServiceImpl extends BaseInfoProperties implements ResumeWorkExpService {

    @Autowired
    private ResumeWorkExpMapper resumeWorkExpMapper;

    /**
     * 保存工作经验
     *
     * @param editWorkExpBO 保存工作经验bo类
     * @return
     */
    @Transactional
    @Override
    public void editWorkExp(EditWorkExpBO editWorkExpBO) {

        String editWorkExpId = editWorkExpBO.getId();
        String userId = editWorkExpBO.getUserId();
        String resumeId = editWorkExpBO.getResumeId();

        ResumeWorkExp resumeWorkExp = new ResumeWorkExp();
        BeanUtils.copyProperties(editWorkExpBO, resumeWorkExp);

        if (StringUtils.isBlank(editWorkExpId)) {
            resumeWorkExp.setCreateTime(LocalDateTime.now());
            resumeWorkExp.setUpdatedTime(LocalDateTime.now());
            resumeWorkExpMapper.insert(resumeWorkExp);
        } else {
            resumeWorkExp.setUpdatedTime(LocalDateTime.now());
            resumeWorkExpMapper.update(resumeWorkExp, new QueryWrapper<ResumeWorkExp>()
                    .eq("id", editWorkExpId)
                    .eq("user_id", userId)
                    .eq("resume_id", resumeId));
        }

        redis.del(REDIS_RESUME_EXPECT + ":" + userId);

    }

    /**
     * 查询工作经验
     *
     * @param workExpId 经验表的id
     * @param userId    用户表的id
     * @return
     */
    @Override
    public ResumeWorkExp getWorkExp(String workExpId, String userId) {

        ResumeWorkExp resumeWorkExp = resumeWorkExpMapper.selectOne(new QueryWrapper<ResumeWorkExp>()
                .eq("id", workExpId)
                .eq("user_id", userId));
        return resumeWorkExp;
    }

    /**
     * 删除工作经验
     *
     * @param workExpId 经验表的id
     * @param userId    用户表的id
     * @return
     */
    @Transactional
    @Override
    public void deleteWorkExp(String workExpId, String userId) {
        resumeWorkExpMapper.delete(new QueryWrapper<ResumeWorkExp>()
                .eq("id", workExpId)
                .eq("user_id", userId));
        redis.del(REDIS_RESUME_INFO + ":" + userId);
    }


}










































































